<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (! Schema::hasTable('seller_categories')) {
            Schema::create('seller_categories', function (Blueprint $table) {
                $table->comment('产品商户分类');
                $table->id()->startingValue(100_000)->comment('ID');
                $table->unsignedBigInteger('seller_id')->comment('商户 ID')->index('seller_id');
                $table->unsignedBigInteger('parent_id')->default(0)->comment('父级分类ID')->index('parent_id');
                $table->integer('position')->default(0)->comment('排序');
                $table->boolean('active')->comment('是否启用');
                $table->timestamps();
            });
        }
        if (! Schema::hasTable('seller_category_descriptions')) {
            Schema::create('seller_category_descriptions', function (Blueprint $table) {
                $table->comment('商户产品分类名称、描述等详情');
                $table->id()->comment('ID');
                $table->unsignedBigInteger('seller_category_id')->comment('分类 ID')->index('seller_category_id');
                $table->string('locale')->comment('语言');
                $table->string('name')->comment('名称');
                $table->text('content')->comment('描述');
                $table->timestamps();
            });
        }
        if (! Schema::hasTable('product_seller_categories')) {
            Schema::create('product_seller_categories', function (Blueprint $table) {
                $table->comment('产品所属商户分类');
                $table->id()->comment('ID');
                $table->unsignedBigInteger('product_id')->comment('产品 ID')->index('product_id');
                $table->unsignedBigInteger('seller_category_id')->comment('商户分类 ID')->index('seller_category_id');
                $table->timestamps();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('seller_categories');
        Schema::dropIfExists('seller_category_descriptions');
        Schema::dropIfExists('product_seller_categories');
    }
};
